// pages/leaveRequest/leaveRequest.js

var util = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		c_id: "",
		s_id: "",
		name: "",
		reason: "",
		sign: true
	},

	inputReason: function(e) {
		//console.log(e);
		this.setData({
			reason: e.detail.value
		})
	},

	submitRequest: function() {
		var that = this;
		const db = wx.cloud.database();
		var time = util.formatTime(new Date());
		const leave = db.collection('Leave');
		that.setData({
			sign: false
		})
		setTimeout(function() {
			wx.navigateBack({
				delta: 1
			})
		}, 2000)
		//调用云函数获取openid
		leave.add({
			data: {
				ds: time,
				course_id: that.data.c_id,
				student_id: that.data.s_id,
				reason: that.data.reason,
				status: 0
			}
		})
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		this.setData({
			c_id: options.id,
			name: options.name,
			s_id: options.studentID
		})


	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
